#define _CRT_SECURE_NO_WARNINGS 1

//https://leetcode.cn/problems/happy-number/description/

class Solution {
public:

    int Happy(int n)
    {
        int sum = 0;
        while (n)
        {
            sum += (n % 10) * (n % 10);
            n /= 10;
        }

        return sum;
    }

    bool isHappy(int n) {
        int slow = n, fast = n;

        while (1)
        {
            slow = Happy(slow);
            fast = Happy(Happy(fast));

            if (slow == fast)
            {
                if (slow == 1)
                {
                    return true;
                }
                return false;
            }
        }
        //return true;
    }
};